<?php

/**
 * zona actions.
 *
 * @package    sf_sandbox
 * @subpackage zona
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class zonaActions extends sfActions
{
    
    public function executeShow(sfWebRequest $request)
  {
    $this->zona = Doctrine_Core::getTable('Zona')->find(array($request->getParameter('id')));
    $this->forward404Unless($this->zona);
  }
  public function executeIndex(sfWebRequest $request)
  {
//    $this->zonas = ZonaTable::getZonas()    ;
 
        $this->zonas = $this->getPager(ZonaTable::getBuscarZonas("", ""), $request->getGetParameter('page'), "Zona");
  
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new ZonaForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new ZonaForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($zona = Doctrine_Core::getTable('Zona')->find(array($request->getParameter('id'))), sprintf('Object zona does not exist (%s).', $request->getParameter('id')));
    $this->form = new ZonaForm($zona);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($zona = Doctrine_Core::getTable('Zona')->find(array($request->getParameter('id'))), sprintf('Object zona does not exist (%s).', $request->getParameter('id')));
    $this->form = new ZonaForm($zona);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
      
    $request->checkCSRFProtection();

    $this->forward404Unless($zona = Doctrine_Core::getTable('Zona')->find(array($request->getParameter('id'))), sprintf('Object zona does not exist (%s).', $request->getParameter('id')));
    $zona->delete();

    $this->redirect('zona/index');
  }
public function executeEliminar(sfWebRequest $request) {
           $this->forward404Unless($this->zona = Doctrine_Core::getTable('Zona')->find(array($request->getParameter('id'))), sprintf('Object zona does not exist (%s).', $request->getParameter('id')));

              
    }
  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $zona = $form->save();
   $this->redirect('zona/index');
//      $this->redirect('zona/edit?id='.$zona->getId());
    }
  }
    protected function getPager($q, $page, $model) {
        $pager = new sfDoctrinePager($model, sfConfig::get('app_nro_x_pagina_contribuyente'));
        $pager->setQuery($q);
        $pager->setPage($page);
        $pager->init();

        return $pager;
    }
    public function executeBuscarZonas(sfWebRequest $request) {
       
        if ($request->isMethod('post')) {
            $nombre = $request->getPostParameter("nombre");
           } else {
            $nombre = $request->getGetParameter("nombre");
          }
      
        $this->zonas = $this->getPager(ZonaTable::getBuscarZonas($nombre), $request->getGetParameter('page'), "Zona");
        if ($request->isXmlHttpRequest()) {
            return $this->renderPartial("zona/listadoZonas", array('zonas' => $this->zonas));
        }
    }
  
    
    
}


